package com.gfxy.modules.items.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gfxy.modules.items.entity.Rcpyfa;
import com.gfxy.modules.items.entity.teachingresult.TeachingResultContent;
import com.gfxy.modules.items.mapper.RcpyfaMapper;
import com.gfxy.modules.items.service.IRcpyfaService;
import com.gfxy.modules.items.vo.*;
import com.gfxy.modules.excel.ExcelUtil;
import org.apache.poi.ss.usermodel.Row;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 人才培养方案
 * @Author: jeecg-boot
 * @Date:   2021-08-07
 * @Version: V1.0
 */
@Service
public class RcpyfaServiceImpl extends AbstractProjectServiceImpl<RcpyfaMapper, Rcpyfa> implements IRcpyfaService {

	protected int memberCellNum = 3;

	@Override
	protected void pass(String id, String isPass) {

	}

	@Override
	protected String[] getMemberArray(Row row) {
		String nameStrs = ExcelUtil.formatCell(row.getCell(memberCellNum));
		return nameStrs.split(memberNameSeparator);
	}

	@Override
	protected Rcpyfa getOneProject(Row row) {
		String date = ExcelUtil.formatCell(row.getCell(0));
		String classess = ExcelUtil.formatCell(row.getCell(1));
		String projectName = ExcelUtil.formatCell(row.getCell(2));
		Rcpyfa rcpyfa = new Rcpyfa();
		rcpyfa.setDate(date);
		rcpyfa.setRcpyfaClassess(translateRcpyfaClassess(classess));
		rcpyfa.setProjectName(projectName);
		rcpyfa.setIsPass(0);
		rcpyfa.setTotalScore(this.getTotalScore(rcpyfa));
		return rcpyfa;
	}



	@Override
	public Double getTotalScore(Rcpyfa rcpyfa) {
		double result = 20.0;
		return result;
	}

	protected double computeProportion(int ranked, int totalNum){
		if(totalNum==1){
			return 1.0;
		} else if(totalNum == 2){
			if(ranked ==1){
				return 0.6;
			} else if(ranked == 2){
				return 0.4;
			} else {
				return 0.0;
			}
		} else if(totalNum == 3){
			if(ranked ==1){
				return 0.5;
			} else if(ranked == 2){
				return 0.3;
			} else if(ranked == 3){
				return 0.2;
			} else {
				return 0.0;
			}
		} else if(totalNum == 4){
			if(ranked ==1){
				return 0.5;
			} else if(ranked == 2){
				return 0.25;
			} else if(ranked == 3){
				return 0.15;
			} else if(ranked == 4){
				return 0.1;
			} else {
				return 0.0;
			}
		} else if(totalNum == 5){
			if(ranked ==1){
				return 0.45;
			} else if(ranked == 2){
				return 0.2;
			} else if(ranked == 3){
				return 0.15;
			} else if(ranked == 4){
				return 0.1;
			} else if(ranked == 5){
				return 0.1;
			} else {
				return 0.0;
			}
		} else if(totalNum == 6){
			if(ranked ==1){
				return 0.45;
			} else if(ranked == 2){
				return 0.2;
			} else if(ranked == 3){
				return 0.15;
			} else if(ranked == 4){
				return 0.1;
			} else if(ranked == 5){
				return 0.05;
			} else if(ranked == 6){
				return 0.05;
			}else {
				return 0.0;
			}
		} else if(totalNum >=6){
			if(ranked == 1){
				return 0.4;
			} else if(ranked == 2){
				return 0.2;
			} else if(ranked == 3){
				return 0.15;
			} else if(ranked > 1){
				return Math.floor(0.2*10000/(totalNum-1))/10000.0 ;
			}else {
				return 0.0;
			}
		} else {
			return 0.0;
		}
	}

	@Override
	public IPage<RcpyfaMemberPage> getRcpyfaMemberPageListByYear(String date, Integer pageNo, Integer pageSize) {
		Page<RcpyfaMemberPage> page = new Page<>(pageNo,pageSize);
		return page.setRecords(this.baseMapper.selectRcpyfaMemberPageListByYear(date));
	}

	@Override
	public List<RcpyfaMemberPage> getRcpyfaMemberPageListByYear(String date) {
		return this.baseMapper.selectRcpyfaMemberPageListByYear(date);
	}
	private int translateRcpyfaClassess(String rcpyfaClassess){
		if(rcpyfaClassess == null || rcpyfaClassess.equals("")){
			return 0;
		} else if(rcpyfaClassess.equals("全日制")){
			return 1;
		} else if(rcpyfaClassess.equals("扩招")){
			return 2;
		} else {
			return 0;
		}
	}

	@Override
	protected List<TeachingResultContent> createTeachingResultContent(Rcpyfa jxcg)  {

		List<TeachingResultContent> result = new ArrayList<>();

		// 类型
		TeachingResultContent classTeachingResultContent = new TeachingResultContent();
		classTeachingResultContent.setType(1);
		classTeachingResultContent.setLevel(jxcg.getRcpyfaClassess());

		try {
			classTeachingResultContent.setValue(dictTranslater.getDictValue(RcpyfaMemberPage.class, "rcpyfaClassess", String.valueOf(jxcg.getRcpyfaClassess())));
			result.add(classTeachingResultContent);
		} catch (NoSuchFieldException e) {
			log.error(e.getMessage(),e);
		}
		return result;
	}

}
